/*
 * EqualIntruction.cpp
 *
 *  Created on: 18/nov/2010
 *      Author: computer
 */

#include "EqualInstruction.h"
#include "Variable.h"
#include <sstream>

namespace TreeExpression {

EqualInstruction::EqualInstruction() : FlowExpression(), Expression_CRTP<EqualInstruction>() { }

EqualInstruction::EqualInstruction(const EqualInstruction& copy) : Expression(copy), FlowExpression(copy), Expression_CRTP<EqualInstruction>(copy) { }

EqualInstruction::~EqualInstruction() { }

AutoPointer<Expression> EqualInstruction::eval(CopyPointer<Context>& context) {
	Variable* var = dynamic_cast<Variable*>(this->getSon().get());
	AutoPointer<Expression> ris = this->getSon()->getLeaf()->eval(context);
	context->addDefinition(var->getName(), ris);
	return ris;
}

std::string EqualInstruction::toString() const {
	std::ostringstream oss;
	oss << this->getSon()->toString() << " = " << this->getSon()->getLeaf()->toString();
	return oss.str();
}

}
